﻿using System.Diagnostics.CodeAnalysis;
using System.Runtime.Versioning;

namespace CommunityToolkit.Maui.Maps;

/// <summary>
/// Maps Extensions for <see cref="MauiAppBuilder"/>
/// </summary>
[SupportedOSPlatform("iOS15.0")]
[SupportedOSPlatform("MacCatalyst15.0")]
[SupportedOSPlatform("Android21.0")]
[SupportedOSPlatform("Windows10.0.17763")]
[SupportedOSPlatform("Tizen6.5")]
public static class AppBuilderExtensions
{
	/// <summary>
	/// Initializes the .NET MAUI Community Toolkit Maps Library
	/// </summary>
	/// <param name="builder"><see cref="MauiAppBuilder"/> generated by <see cref="MauiApp"/> </param>
	/// <param name="key"></param>
	/// <returns><see cref="MauiAppBuilder"/></returns>
	/// <remarks>
	/// In order to use the .NET MAUI Community Toolkit Maps you need to call the extension method in your `MauiProgram.cs` file as follows:
	/// </remarks>
	/// <example>
	/// <code>
	/// public static MauiApp CreateMauiApp()
	///	{
	///		var builder = MauiApp.CreateBuilder();
	///		builder
	///			.UseMauiApp&amp;lt;App&amp;gt;()
	///	
	/// #if WINDOWS
	///			// Initialize the .NET MAUI Community Toolkit Maps by adding the below line of code
	///			.UseMauiCommunityToolkitMaps("key")
	///	#else
	///			.UseMauiMaps()
	///	#endif	
	///
	///		// Continue initializing your .NET MAUI App here
	///
	///		return builder.Build();
	/// }	
	/// </code>
	/// </example>
	/// 
	public static MauiAppBuilder UseMauiCommunityToolkitMaps(this MauiAppBuilder builder, string key)
	{
		builder.ConfigureMauiHandlers(handlers =>
		{
#if WINDOWS
			Handlers.MapHandlerWindows.MapsKey = key;
			IMauiHandlersCollection mauiHandlersCollection = handlers.AddHandler<Microsoft.Maui.Controls.Maps.Map, Handlers.MapHandlerWindows>();
#endif
		});

		return builder;
	}
}